﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using DragDraw.Util;
using DragDraw.UserService;

namespace DragDraw.Tool
{
    public partial class ChatRoom : UserControl
    {
        WidgetServiceProxy m_service;
        bool m_joined = false;
        public ChatRoom()
        {
            InitializeComponent();
        }

        void OnReceive(object sender, OnUpdateSessionEventArgs e)
        {
            TxtMain.Text += "\n" + e.Result.UserID + " 说： " + e.Result.Value;
            PanelText.ScrollToVerticalOffset(PanelText.ExtentHeight - PanelText.ViewportHeight);
        }

        private void BtnSend_Click(object sender, RoutedEventArgs e)
        {
            m_service.UpdateDuplexSession("chatting",TxtSend.Text);
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            if (!m_joined)
            {
                m_service = OperationManager.Instance.CreateWidgetServiceProxy(this);
                m_service.OnDuplexSessionUpdate += OnReceive;

                m_service.JoinDuplexSession("chatting");
                m_joined = true;
            }
        }
    }
}
